﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Nova_Common;
using Nova_MOD;
using Nova_BLL;
using Nova_DAL;
using System.Data.SqlClient;
using System.Data.Common;

public partial class Views_TrayMaterial : System.Web.UI.Page
{
    string lbl_LaneNo = ""; //巷道号
    string cid = "";        ////层
    int rid = 0;        //gridview行的编号
    int iLcol = 0;
    string PosID = "";

    DataSet ds = null;
    DataTable myTable = null;

    int iLineNo = 0;               //排
    int iLayNo = 0;           //层

    DbHelper access = new DbHelper();

    Nova_Common.LoginLogic cLoginLogic = new LoginLogic();
    Nova_BLL.TBase_Position Nova_BLL_TBase_Position = new Nova_BLL.TBase_Position();
    Nova_BLL.TLaneDefine Nova_BLL_TLaneDefine = new Nova_BLL.TLaneDefine();
    Nova_BLL.TPosState Nova_BLL_TPostState = new Nova_BLL.TPosState();
    Nova_MOD.TBase_Position Nova_MOD_TBase_Position = new Nova_MOD.TBase_Position();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Nova_Common.LoginLogic.IsLogin();
            ddlbind();
            gvbind();

        }
    }


    protected void ddlbind()
    {
        ds = Nova_BLL_TLaneDefine.DataSetTLaneDefine();
        if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        {
            ddlNo_Lane.DataSource = ds;
            ddlNo_Lane.DataValueField = "No_Lane";
            ddlNo_Lane.DataTextField = "No_Lane_Text";
            ddlNo_Lane.DataBind();
        }
    }
    protected bool reInt(string strNum)
    {
        try
        {
            int var1 = Convert.ToInt32(strNum);
            return true;
        }
        catch
        {
            return false;
        }
    }


    protected void gvbind()
    {
        lbl_LaneNo = ddlNo_Lane.SelectedValue.ToString();
        myTable = Nova_BLL_TBase_Position.DTableTBase_Position(lbl_LaneNo);
        if (myTable != null && myTable.Rows.Count > 0)
        {
            GV.DataSource = myTable;
            GV.DataBind();
        }
    }

    protected void ddlNo_Lane_SelectedIndexChanged(object sender, EventArgs e)
    {
        gvbind();
    }



    protected void GV_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[1].Attributes["style"] = "width:30px;";
            cid = e.Row.Cells[1].Text.ToString().Substring(0, 1);
            rid = e.Row.RowIndex + 1;
            lbl_LaneNo = ddlNo_Lane.SelectedValue.ToString();       //巷道号
            iLineNo = Convert.ToInt32(e.Row.Cells[0].Text.Substring(0, 1));     //排
            //iLcol = e.Row.RowIndex;         //列
            iLayNo = Convert.ToInt32(e.Row.Cells[1].Text.Substring(0, 1));     //层
            DataRowView dv = (DataRowView)e.Row.DataItem;
            for (int i = 0; i < e.Row.Cells.Count; i++)        
            {
                //列处理  列号从1开始
                if (i == 0)
                {
                    iLcol = 1;
                }
                else if (i == 1)
                {
                    iLcol = 1;
                }
                else
                {
                    iLcol = i-1;
                }

                //列号从2开始
                //if (i == 0)
                //{
                //    iLcol = 2;
                //}
                //else if (i == 1)
                //{
                //    iLcol = 2;
                //}
                //else
                //{
                //    iLcol = i;
                //}


                if (i > 1)
                {
                    
                    PosID = "10" + lbl_LaneNo.PadLeft(2, '0') + iLineNo.ToString() + iLcol.ToString().PadLeft(3, '0') + iLayNo.ToString().PadLeft(2, '0') + "00";
                    e.Row.Cells[i].Attributes["onclick"] = string.Format("window.showModalDialog('MetarPOP.aspx?PosID={0}', window, 'dialogWidth=710px;dialogHeight=450px;scroll:no;resizable:no;status:0;');", PosID);

                    e.Row.Cells[i].Text = Nova_BLL_TPostState.strPosImg(e.Row.Cells[i].Text.ToString());

                }

            }
        }
    }




    protected void ibtnReset_Click(object sender, ImageClickEventArgs e)
    {
        gvbind();
    }
}
